<%@page import="com.lrkj.back.entity.ZsEquip" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
    <script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>
    <script type="text/javascript" src="${ctx}/js/mask.js"></script>

    <title>BD测试</title>
    <style type="text/css">
        td {
            text-align: center;
        }
    </style>
</head>
<body>
<div id="mask" class="mask"></div>
<div id="saper-container">
    <div class="wrap clearfix">
        <div class="content">
            <div class="subfiled clearfix">
                <h2>BD测试</h2>
            </div>
            <div class="tab-container" data-trigger="click">
                <div class="tab">
                    <a href="javascript:;" class="current">选择设备</a>
                    <a href="javascript:;">结束测试</a>
                    <a href="javascript:;">测试审核</a>
                </div>
                <div class="tab-content">
                    <!--表格具体内容-->
                    <div class="tab-content-item">
                        <div class="table">
                            <div class="table-box">
                                <form class="saper-form" id="dataForm">
                                    <div class="kv-item clearfix">
                                        <label>测试设备：</label>
                                        <div class="kv-item-content">
                                            <select id="equipId" name="ceshiEquipId" onChange="showSoft()">
                                                <c:if test="${lstEquips != null}">

                                                    <option value="">请选择</option>
                                                    <c:forEach items="${lstEquips }" var="equip">
                                                        <option value="${equip.equipId }">${equip.equipName }</option>
                                                    </c:forEach>
                                                </c:if>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="kv-item clearfix">
                                        <label>测试程序：</label>
                                        <div class="kv-item-content">
                                            <!-- <input type="texe" name="ceshiSoft" value="测试程序"> -->
                                            <select id="seop" name="ceshiSoft">
                                                <option>请选择</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="kv-item clearfix">
                                        <label>测试人：</label>
                                        <div class="kv-item-content">
                                            <input type="text" name="ceshirenTiaoma" placeholder="测试人" id="csr"
                                                   onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                                        </div>
                                    </div>
                                    <div class="kv-item clearfix">
                                        <label></label>
                                        <div class="kv-item-content">
                                            <a href="javascript:;" class="sapar-btn sapar-btn-recom query-btn"
                                               id="kaishi">开始测试</a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <!--表格结束-->
                    <div class="tab-content-item">
                        <div class="table">
                            <!--表格具体内容-->
                            <div class="table-box">
                                <form action="" id="ceshiJieshu">
                                    <div id="table_left" class="table">
                                        <!--表格具体内容-->
                                        <div class="table-box">
                                            <table>
                                                <thead>
                                                <tr>
                                                    <th><input type="checkbox" id="checkall" name="checkall"/></th>
                                                    <th>测试流水</th>
                                                    <th>测试机器</th>
                                                    <th>测试软件</th>
                                                    <th>测试人</th>
                                                    <th>测试开始时间</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <%-- <c:if test="${lstCeshi != null}">
                                                    <!-- var 是给给他起名字 -->
                                                    <c:forEach items="${lstCeshi}" var="ceshi">
                                                        <tr>
                                                            <td>
                                                            <input type="checkbox" name="ceshiLiushui"
                                                                value=${ceshi.ceshiLiushui } />
                                                            </td>
                                                            <td>${ceshi.ceshiLiushui }</td>
                                                            <td>${ceshi.equip.equipName}</td>
                                                            <td>${ceshi.ceshiSoft}</td>
                                                            <td>${ceshi.employee.employeeName}</td>
                                                            <td><fmt:formatDate value="${ceshi.ceshiKaishiTime}"
                                                                    type="date" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                                                        </tr>
                                                    </c:forEach>
                                                </c:if> --%>
                                                <c:if test="${lstCeshi != null}">
                                                    <c:forEach items="${lstCeshi }" var="cs">
                                                        <tr>
                                                            <td><input type="checkbox" name="ceshiLiushui"
                                                                       value=${cs.ceshiLiushui }/></td>
                                                            <td>${cs.ceshiLiushui }</td>
                                                            <td>${cs.equip.equipName}</td>
                                                            <td>${cs.ceshiSoft}</td>
                                                            <td>${cs.employee.employeeName}</td>
                                                            <td><fmt:formatDate value="${cs.ceshiKaishiTime}"
                                                                                type="date"
                                                                                pattern="yyyy-MM-dd HH:mm:ss"/></td>

                                                        </tr>
                                                    </c:forEach>
                                                </c:if>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div><!--表格结束-->
                                </form>
                                <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="end">结束测试</a>
                            </div>
                        </div>
                        <!--表格结束-->
                    </div>
                    <div class="tab-content-item">
                        <!--表格具体内容-->
                        <div class="table">
                            <div class="table-box">
                                <form action="" id="ceshiShenhe">
                                    <div id="table_left" class="table">
                                        <!--表格操作-->
                                        <!--表格具体内容-->
                                        <div class="table-box">
                                            <table>
                                                <thead>
                                                <tr>
                                                    <th>测试流水</th>
                                                    <th>测试机器</th>
                                                    <th>测试软件</th>
                                                    <th>测试人名称</th>
                                                    <th>测试开始时间</th>
                                                    <th>审核</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <c:if test="${lstShenhe != null}">
                                                    <!-- var 是给给他起名字 -->
                                                    <c:forEach items="${lstShenhe}" var="ceshi">
                                                        <tr data="${ceshi.ceshiLiushui}" class="miejunData">
                                                            <td>${ceshi.ceshiLiushui }<input type="hidden"
                                                                                             name="ceshiLiushui"
                                                                                             value="${ceshi.ceshiLiushui }">
                                                            </td>
                                                            <td>${ceshi.equip.equipName}</td>
                                                            <td>${ceshi.ceshiSoft}</td>
                                                            <td>${ceshi.employee.employeeName}</td>
                                                            <td><fmt:formatDate value="${ceshi.ceshiKaishiTime}"
                                                                                type="date"
                                                                                pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                                            <td>
                                                                <select name="ceshiHege">
                                                                    <option value="1">通过</option>
                                                                    <option value="2">不通过</option>
                                                                </select>
                                                            </td>

                                                        </tr>
                                                    </c:forEach>
                                                </c:if>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div><!--表格结束-->
                                </form>
                                <a href="javascript:;" class="sapar-btn sapar-btn-recom" id="baocun">保存</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function showSoft() {
            var url = "${ctx}/soft/findCeshiChengxu.do?equipId=" + $("#equipId").val();
            $.ajax({
                type: "POST",
                url: url,
                data: "equipId",// 你的formid
                error: function (request) {
                    layer.alert("网络故障，请稍后再试!");
                },
                success: function (data) {
                    if (data.status == "true") {
                        $("#seop").empty();
                        var soft = data.lstSofts;
                        var str = '';
                        for (var i = 0; i < soft.length; i++) {
                            str += '<option id="seoption" value="' + soft[i].softId + '">' + soft[i].softName + '</option>';
                        }
                        $("#seop").append(str);
                    }
                }
            });
        }
        $(function () {
// 	var totalPage = ${total};
// 	var pageNo = getParameter('pageIndex');
// 	if(!pageNo){
// 		pageNo = 1;
// 	}
// 	kkpager.generPageHtml({
// 		pno : pageNo,
// 		//总页码
// 		total : totalPage,
// 		//链接前部
// 		hrefFormer : '${ctx}/miejun/bdCeshiShenhe',
// 		//链接尾部
// 		hrefLatter : '.do',
// 		getLink : function(n){
// 			return this.hrefFormer + this.hrefLatter + "?pageIndex="+n+"&searchTxt="+$(".search_text").val();
// 		}
// 	});

            //开始测试保存用到的方法
            $("#kaishi").click(function () {
                var btn = true;
                var txt = $("#csr").val();
                $("select").each(function () {
                    if ($(this).val() == '') {
                        btn = false;
                        alert("请选择");
                        return false;
                    }
                });
                if (isNullOrEmpty(txt)) {
                    btn = false;
                    alert("请输入测试人");
                    return false;
                }
                if (btn) {
                    showMask();
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/miejun/startCeshi.do?testMan=" + txt,
                        data: $('#dataForm').serialize(),
                        error: function (request) {
                            layer.alert("网络故障，请稍后再试!");
                        },
                        success: function (data) {
                            $("#mask").hide();
                            if (data.state == "true") {
                                layer.alert("保存成功", function () {
                                    window.location.href = "${ctx}/miejun/bdCeshi.do";
                                });
                            } else {
                                alert(data.msg);
                            }

                            ;
                        }
                    });
                }
            });
            $("#end").click(function () {
                var chk_value = getSelRecord();
                if (chk_value.length > 0) {
                    showMask();
                    $.ajax({
                        type: "post",
                        url: "${ctx}/miejun/endCeshi.do?id=" + chk_value.join(),
                        error: function () {
                            layer.alert("网络故障，稍后再试");
                        },
                        success: function (data) {
                            $("#mask").hide();
                            if (data.state == "true") {
                                layer.alert("保存成功", function () {
                                    window.location.reload();
                                    $("input[name='ceshiLiushui']").each(function () {
                                        $("input[name='ceshiLiushui']").prop('checked', false);
                                    });
                                    $("input[name='checkall']").prop('checked', false);
                                });
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    });
                }
                else {
                    layer.alert("请先选择数据！");
                }
            });

            $("#baocun").click(function () {
                showMask();
                $.ajax({
                    type: "post",
                    url: "${ctx}/miejun/clickShenhe.do",
                    data: $("#ceshiShenhe").serialize(),
                    error: function () {
                        layer.alert("网络故障，稍后再试");
                    },
                    success: function (data) {
                        $("#mask").hide();
                        if (data.state == "true") {
                            layer.alert("保存成功", function () {
                                window.location.href = "${ctx}/miejun/bdCeshi.do";
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                    }
                });
            });

            $("#checkall").click(function () {
                if (this.checked) {
                    $("input[name='ceshiLiushui']").prop('checked', true)
                } else {
                    $("input[name='ceshiLiushui']").prop('checked', false)
                }
            });
        });
        function isNullOrEmpty(strVal) {
            strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
            if (strVal == '' || strVal == null || strVal == undefined) {
                return true;
            } else {
                return false;
            }
        }
        function getSelRecord() {
            var chk_value = [];
            $('input[name="ceshiLiushui"]:checked').each(function () {
                chk_value.push($(this).val());
            });
            return chk_value;
        }
        function getParameter(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
    </script>
</body>
</html>